	Note: the following code is meant to illustrate the technique required for spooling a 
	picture out to a file. It is meant to be a guide only; do not use the code until you 
	understand it thoroughly. For more information on Signals see Macintosh Technical 
	Note #88.


{the following variables and procedure must be at the main level of the program}
	VAR	PICTCount: LONGINT; {the current size of the picture}
		globalRef: INTEGER; {the file system reference number}
		newPICTHand: PicHandle;


	{this is the replacement for the StdPutPic routine}
	PROCEDURE PutPICTData(dataPtr: Ptr; byteCount:INTEGER);
	  VAR
		longCount: LONGINT;
		err : INTEGER;
	  BEGIN {unfortunately, we don't know what to do with errors}
	  longCount := byteCount; PICTCount := PICTCount + byteCount;
	  err := FSWrite (globalRef, longCount, dataPtr); {ignore errorÉ}
	  IF newPICTHand <> NIL THEN
	    newPICTHand^^.picSize := PICTCount; {update so
			  QD can track the size for oddness and pad out to full words}
	  END;

   {Note that this assumes the picture is entirely in memory which wouldn't
	always be the case. You could (in effect) be feeding the StdGetPic
	procedure at the same time, or simply spooling while drawing.}
	PROCEDURE SpoolOutPICTFile(PICTHand: PicHandle{the picture to spool});
	  VAR
		err: OSErr;
		i: INTEGER;
		wher: Point;	  { where to display dialog }
		longCount,
		longZero: LONGINT;
		pFrame: Rect;
		reply: SFReply;	  { reply record }
		myProcs: QDProcs; {use CQDProcs for a CGrafPort (a color window)}
	  BEGIN
	   wher.h:=20;
	   wher.v:=20;
	   {get a file to output to}
	   SFPutFile (wher, 'Save the PICT as:', 'untitled', NIL, reply);
	   IF reply.good THEN
		   BEGIN
		   err := Create (reply.fname, reply.vrefnum, '????', 'PICT');
		   IF (err = noErr) | (err = dupFNErr) THEN
		     BEGIN
		     {now open the target file and prepare to spool to it}
			 Signal(FSOpen(reply.fname, reply.vrefnum, globalRef));
			 SetStdProcs(myProcs); {use SetStdCProcs for a CGrafPort}
			 myWindow^.grafProcs := @myProcs;
			 myProcs.putPicProc := @PutPICTData;
			 
			 longZero := 0; 
			 longCount := 4; PICTCount := SizeOf(Picture);
			 {now write out the 512 byte header and zero (initially) the
			  Picture structure}
			 FOR i := 1 TO 512 DIV 4 + SizeOf(Picture) DO
			   Signal(FSWrite (globalRef, longCount, @longZero));

			 {open a new picture and draw the old one to it; this will convert
			 the old picture to fit the type of GrafPort to which we are
			 currently set}
			 pFrame := PICTHand^^.picFrame; newPICTHand := NIL;
			 newPICTHand := OpenPicture (pFrame);
			 DrawPicture (PICTHand, pFrame); {draw the picture so the
			  bottleneck will be used. In real life you could be spooling
			  while doing drawing commands (you might not use DrawPicture)}
			 ClosePicture;
	   
			 Signal(SetFPos (globalRef, fsFromStart, 512)); {skip the MacDraw
															 header}
			 longCount := SizeOf(Picture);
			 {write out the correct (low word of the) size and the frame at
			  the beginning}
		     Signal(FSWrite (globalRef, longCount, Ptr(newPICTHand^)));

		     Signal(FSClose (globalRef) );

		     myWindow^.grafProcs := NIL;
		     KillPicture (newPICTHand);
			 END ELSE Signal(err);
		END; {IF reply.good}
	END; {OutPICT}
